import config from "@renderer/config"
import api from '@renderer/api'
import tool from '@renderer/utils/tool'
import http from "@renderer/utils/request"
import {permission, rolePermission} from '@renderer/utils/permission'
import auth from '@renderer/directives/auth'
import auths from '@renderer/directives/auths'
import authsAll from '@renderer/directives/authsAll'
import role from '@renderer/directives/role'
import time from '@renderer/directives/time'
import copy from '@renderer/directives/copy'
import errorHandler from '@renderer/utils/errorHandler'
import * as elIcons from '@element-plus/icons-vue'
import * as scIcons from '@renderer/assets/icons'

export default {
	install(app) {
		//挂载全局对象
		app.config.globalProperties.$CONFIG = config;
		app.config.globalProperties.$TOOL = tool;
		app.config.globalProperties.$HTTP = http;
		app.config.globalProperties.$API = api;
		app.config.globalProperties.$AUTH = permission;
		app.config.globalProperties.$ROLE = rolePermission;

		//注册全局组件


		//注册全局指令
		app.directive('auth', auth)
		app.directive('auths', auths)
		app.directive('auths-all', authsAll)
		app.directive('role', role)
		app.directive('time', time)
		app.directive('copy', copy)

		//统一注册el-icon图标
		for(let icon in elIcons){
			app.component(`ElIcon${icon}`, elIcons[icon])
		}
		//统一注册sc-icon图标
		for(let icon in scIcons){
			app.component(`ScIcon${icon}`, scIcons[icon])
		}

		//关闭async-validator全局控制台警告
		window.ASYNC_VALIDATOR_NO_WARNING = 1

		//全局代码错误捕捉
		app.config.errorHandler = errorHandler
	}
}
